home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / origami / foldhelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  6.6 KB  |  281 lines

  1. /*{{{}}}*/
  2. /*{{{  #includes*/
  3. #ifdef CONFIG_H
  4. #   include "config.h"
  5. #endif
  6.  
  7. #include <sys/types.h>
  8. #include <unistd.h>
  9. #include <limits.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13.  
  14. #define FOLDHELP_C
  15. #define I_LOOP_C
  16. #define I_DISPLAY_C
  17. #define I_FINDS_C
  18. #define I_FOLDING_C
  19. #define I_GETMSG_C
  20. #define I_GETTK_C
  21. #define I_ORIEDT_C
  22. #define I_PROMPT_C
  23. #define I_SCREEN_C
  24.  
  25. #include "origami.h"
  26. #include <lib/ori_add_lib.h>
  27. /*}}}  */
  28.  
  29. /*{{{  check_fold*/
  30. public void check_fold(element * const p)
  31. { bd.f.Start_of_fold=p;
  32.   bd.f.End_of_fold = bd.f.Start_of_fold->x.fold.other_end;
  33.   bd.f.Line_after_fold = bd.f.Start_of_fold->next;
  34.   bd.f.End_of_fold->next = bd.f.Line_after_fold;
  35. }
  36. /*}}}  */
  37. /*{{{  to_start*/
  38. public int to_start(int const m)
  39. {
  40.   int dist_to_start;
  41.   element const *p;
  42.  
  43.   dist_to_start = 1;
  44.   p = bd.f.current;
  45.   while (p != bd.f.head->next && dist_to_start <= m)
  46.    { dist_to_start++;
  47.      p = p->prec;
  48.    }
  49.   return dist_to_start;
  50. }
  51. /*}}}  */
  52. /*{{{  to_bottom*/
  53. public int to_bottom(int const m)
  54. {
  55.   int dist_to_end;
  56.   element const *p;
  57.  
  58.   dist_to_end = 0;
  59.   p = bd.f.current;
  60.   while (p != bd.f.tail && dist_to_end <= m)
  61.    { dist_to_end++;
  62.      p = p->next;
  63.    }
  64.   return dist_to_end;
  65. }
  66. /*}}}  */
  67. /*{{{  move_down*/
  68. public void move_down(void)
  69. {
  70.   boolean do_highlight;
  71.  
  72.   if (bd.f.current == bd.f.tail)
  73.    /*{{{  complain and return*/
  74.    { verbose_msg_message(M_BOTTOM);
  75.      return;
  76.    }
  77.    /*}}}  */
  78.   /*{{{  move, count lines and handle status line*/
  79.   ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  80.   title_op((bd.f.cur_line_typ&(START_FOLD|START_FILED))?CHGXY:INCY);
  81.   bd.f.current = bd.f.current->next;
  82.   bd.f.cur_line_typ=get_linetyp(*bd.f.current);
  83.   do_highlight=   (bd.m.select_mode!=no_selection)
  84.                && upd_highlight(bd.f.real_head,bd.f.real_tail,False);
  85.   if (!(bd.f.cur_line_typ&NOT_FOLD) && bd.f.count_comment_line)
  86.      title_op(CHGXY);
  87.   /*}}}  */
  88.  /*{{{  update screen*/
  89.  /*{{{  scroll or redraw*/
  90.   if (bd.scr.cursor.h > (bd.scr.txt_size.h-2) && bd.scr.end != bd.f.tail)
  91.      if (!(al && dl))
  92.       { restore_element(bd.scr.txt_size.h/2);
  93.         return;
  94.       }
  95.      else
  96.         for
  97.          ( bd.scr.cursor.h++
  98.          ; bd.scr.cursor.h>bd.scr.txt_size.h/2
  99.          ;
  100.          )
  101.          { int y;
  102.  
  103.            y=bd.scr.cursor.h;
  104.            whole_screen_up();
  105.            if (y==bd.scr.cursor.h)
  106.               break;
  107.          }
  108.  else
  109.     bd.scr.cursor.h++;
  110.  /*}}}  */
  111.  if (do_highlight)
  112.   /*{{{  correct highlighting of changed line*/
  113.   { write_dsp_line(bd.f.current->prec,bd.scr.cursor.h-1);
  114.     write_dsp_line(bd.f.current,bd.scr.cursor.h);
  115.   }
  116.   /*}}}  */
  117.  /*}}}  */
  118. }
  119. /*}}}  */
  120. /*{{{  move_up*/
  121. public void move_up(void)
  122. {
  123.   boolean do_highlight;
  124.  
  125.   if (bd.f.current->prec == bd.f.head)
  126.    /*{{{  complain and return*/
  127.    { verbose_msg_message(M_TOP);
  128.      return;
  129.    }
  130.    /*}}}  */
  131.   /*{{{  go up, count lines and show status line*/
  132.   ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  133.   if (bd.f.count_comment_line && !(bd.f.cur_line_typ&NOT_FOLD))
  134.      title_op(CHGXY);
  135.   bd.f.current = bd.f.current->prec;
  136.   bd.f.cur_line_typ=get_linetyp(*bd.f.current);
  137.   do_highlight=   (bd.m.select_mode!=no_selection)
  138.                && upd_highlight(bd.f.real_head,bd.f.real_tail,False);
  139.   title_op((bd.f.cur_line_typ&(START_FOLD|START_FILED))?CHGXY:DECY);
  140.   /*}}}  */
  141.   /*{{{  update screen*/
  142.   /*{{{  scroll or redraw*/
  143.   if (bd.scr.start->prec != bd.f.head && bd.scr.cursor.h < 3)
  144.      if (!(al && dl))
  145.       { restore_element(bd.scr.txt_size.h/2);
  146.         return;
  147.       }
  148.      else
  149.       /*{{{  scroll screen*/
  150.         for
  151.          ( bd.scr.cursor.h--
  152.          ; bd.scr.cursor.h<bd.scr.txt_size.h/2
  153.          ;
  154.          )
  155.          { int y;
  156.         
  157.            y=bd.scr.cursor.h;
  158.            whole_screen_down();
  159.            if (y==bd.scr.cursor.h)
  160.               break;
  161.          }
  162.       /*}}}  */
  163.   else
  164.      bd.scr.cursor.h--;
  165.   /*}}}  */
  166.   if (do_highlight)
  167.    /*{{{  correct changed line*/
  168.    { write_dsp_line(bd.f.current->next,bd.scr.cursor.h+1);
  169.      write_dsp_line(bd.f.current,bd.scr.cursor.h);
  170.    }
  171.    /*}}}  */
  172.   /*}}}  */
  173. }
  174. /*}}}  */
  175. /*{{{  skip_to*/
  176. public void skip_to(element * const line)
  177. {
  178.   int level;
  179.  
  180.   if ((level=on_screen(line)))
  181.    { void (*op)();
  182.  
  183.      op=(level>bd.scr.cursor.h)?move_down:move_up;
  184.      while (bd.f.current!=line)
  185.         op();
  186.    }
  187.   else
  188.    { bd.f.cur_line_typ=get_linetyp(*(bd.f.current=line));
  189.      title_op(CHGXY);
  190.      if (bd.m.select_mode)
  191.         upd_highlight(bd.f.real_head,bd.f.real_tail,True);
  192.      restore_element(DEF_CURSOR_LINE);
  193.    }
  194.   ori_assert(bd.f.cur_line_typ==get_linetyp(*bd.f.current),"check cur_linetyp");
  195. }
  196. /*}}}  */
  197. /*{{{  undel_before*/
  198. public void undel_before(element * const ptr_to_new)
  199. {
  200.   insert_link_before(ptr_to_new);
  201.   if (bd.scr.end_level == bd.scr.txt_size.h)
  202.      bd.scr.end = bd.scr.end->prec;
  203.   else
  204.      bd.scr.end_level++;
  205.   if (bd.scr.cursor.h < bd.scr.txt_size.h)
  206.      down_a_bit(bd.scr.cursor.h);
  207.   else
  208.      clrbuffline(bd.scr.txt_size.h,1);
  209.   write_dsp_line(bd.f.current, bd.scr.cursor.h);
  210. }
  211. /*}}}  */
  212. /*{{{  undel_pick_before*/
  213. public void undel_pick_before(void)
  214. {
  215.   element *p, *sf, *ef;
  216.  
  217.   ef=proc_new_element();
  218.   join_links(pick_tail, ef);
  219.   p = pick_head->next;
  220.   sf=proc_new_element();
  221.   join_links(pick_head, sf);
  222.   join_links(sf, p);
  223.   set_linetyp(*sf,START_FOLD);
  224.   sf->x.fold.data = sf->next;
  225.   sf->x.fold.other_end = ef;
  226.   set_linetyp(*ef,END_FOLD);
  227.   ef->x.fold.other_end = sf;
  228.   undel_before(sf);
  229.   pick_tail = pick_head;
  230.   ocl_var[var_kill_count].v--;
  231. }
  232. /*}}}  */
  233. /*{{{  append_to_pick*/
  234. public void append_to_pick(element * const pick_ptr)
  235.  {
  236.    if (pick_ptr)
  237.     { join_links(pick_tail,pick_ptr);
  238.       pick_ptr->indent = 0;
  239.       pick_tail=pick_ptr;
  240.       ocl_var[var_kill_count].v++;
  241.     }
  242.  }
  243. /*}}}  */
  244. /*{{{  undel_after*/
  245. public void undel_after(element * const ptr_to_new)
  246. {
  247.   element *ptr_to_next;
  248.  
  249.   /*note bd.f.current<>bd.f.tail*/
  250.   ptr_to_next = bd.f.current->next;
  251.   join_links(bd.f.current, ptr_to_new);
  252.   join_links(ptr_to_new, ptr_to_next);
  253.   if (bd.scr.cursor.h == bd.scr.txt_size.h)
  254.    { bd.scr.end = bd.scr.end->prec;
  255.      whole_screen_up();
  256.    }
  257.   else
  258.    { if (bd.scr.end_level == bd.scr.txt_size.h)
  259.         bd.scr.end = bd.scr.end->prec;
  260.      else
  261.         bd.scr.end_level++;
  262.      down_a_bit(bd.scr.cursor.h+1);
  263.      write_dsp_line(ptr_to_new, bd.scr.cursor.h + 1);
  264.    }
  265.   move_down();
  266. }
  267. /*}}}  */
  268. /*{{{  pre_remove_line*/
  269. public void pre_remove_line(element ** const p)
  270. {
  271.   element *prec_ptr;
  272.  
  273.   *p = bd.f.current;
  274.   prec_ptr = bd.f.current->prec;
  275.   if (bd.scr.start == bd.f.current)
  276.      bd.scr.start = bd.f.current->next;
  277.   bd.f.current = bd.f.current->next;
  278.   join_links(prec_ptr, bd.f.current);
  279. }
  280. /*}}}  */
  281.